package com.ymttest.business.database;

import java.util.List;
import java.util.Map;
import java.util.Random;

import com.ymt.util.DataManager;
import com.ymttest.database.sqlwapper.YmtCatalogsWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.utils.TestDataManager;

/************************************************************************************
 * 用于生成压测测试数据
 * 
 * @File name : Test.java
 * @Author : zhouyi
 * @Date : 2015年5月21日
 * @Copyright : 洋码头
 ************************************************************************************/
public class CreatePlatformData {
	/**
	 * 用于生成活动api 脚本 GetListByCatalogs改 数据文件
	 * 
	 * @throws InterruptedException
	 */
	public void createCatalogIdListFile() throws InterruptedException {
		DataManager dm = new DataManager();
		TestDataManager.removeFile("./GetListByCatalogs.dat");
		DataManager.appendFileToLien("./GetListByCatalogs.dat", "cidl");
		List<String> list = new YmtCatalogsWapper().selectCatalogIdList();
		for (int num = 0; num < 5000; num++) {
			String temp = "";
			for (int i = 0; i < 40; i++) {
				temp = temp + "\"" + list.get(new Random().nextInt(list.size() - 1)) + "\"\",\"";
			}
			temp = temp.substring(0, temp.length() - 3);
			DataManager.appendFileToLien("./GetListByCatalogs.dat", temp);
		}
	}

	/**
	 * 用于生成活动api 脚本 GetActivityInfosByProductIds改 数据文件
	 * 
	 * @throws InterruptedException
	 */
	public void createProductIdsListFile() throws InterruptedException {
		DataManager dm = new DataManager();
		TestDataManager.removeFile("./GetActivityInfosByProductIds.dat.dat");
		DataManager.appendFileToLien("./GetActivityInfosByProductIds.dat", "pidl");
		List<String> list = new YmtProductsInActivityWapper().selectProductListInActivity();
		for (int num = 0; num < 5000; num++) {
			String temp = "";
			for (int i = 0; i < 40; i++) {
				temp = temp + "\"" + list.get(new Random().nextInt(list.size() - 1)) + "\"\",\"";
			}
			temp = temp.substring(0, temp.length() - 3);
			DataManager.appendFileToLien("./GetActivityInfosByProductIds.dat", temp);
		}
	}

	/**
	 * 用isellerid账号创建活动，数据库操作，可用于功能和压测
	 * 
	 * @param isellerid
	 *            商家id
	 * @throws InterruptedException
	 */
	public void insertActiveInfo(int isellerid) throws InterruptedException {
		Map productinfomap = ProductInfo.createProduct(isellerid, -1);
		ActivityInfo.createActivityBySproductid(isellerid, (String) productinfomap.get("sproductid"));
	}

	public static void main(String args[]) throws InterruptedException {
		new CreatePlatformData().createCatalogIdListFile();
		new CreatePlatformData().createProductIdsListFile();
		// for(int i=0;i<200;i++){
		// new CreatePlatformData().insertActiveInfo(1362788);
		// }

	}
}
